package cli

import (
	"fmt"
	"gitee.com/runx/gitctl/pkg/api/conf"
	v1 "gitee.com/runx/gitctl/pkg/api/v1"
	"gitee.com/runx/gitctl/pkg/cli/ops"
)

func New(c *conf.Config) *Cli {
	curCtx := c.Contexts[c.CurrentContext]
	curServer := c.Servers[curCtx.Server]
	curRepo := c.Repos[curCtx.Repo]
	curUser := c.Users[curCtx.User]
	return &Cli{
		Url:   fmt.Sprintf("%s/api/v1/repos/%s", curServer.Url, curRepo.Uri),
		Token: curUser.Token,
	}
}

type Cli struct {
	Url   string
	Token string
	Body  string
}

func (c *Cli) NewCtx(op ops.Op, res *v1.Resource) *CliContext {
	return &CliContext{
		Url:   c.Url,
		Token: c.Token,
		Op:    op,
		Res:   res,
	}
}


